﻿<%--<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<TrainingRequest.Models.TrainingsSchedules>>" %>--%>
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<List<CRM.Database.Model.TrainingsSchedules>>" %>
<%@ Import Namespace="System.Threading" %>
<%@ Import Namespace="CRM.Database.Model" %>

<%
    var coursesCol = new TrainingsCoursesCollection();
    var placesCol = new TrainingsPlacesCollection();
%>

<%
    Html.DevExpress().GridView(settings =>
                                    {
                                        settings.Name = "gdTrainingsSchedule";
                                        settings.KeyFieldName = "IdTrainingsSchedule";
                                        settings.CallbackRouteValues = new { Controller = "TC", Action = "TrainingsSchedulesPartial" };
                                        settings.SettingsPager.PageSize = 20;
                                        settings.Settings.ShowFilterRow = false;
                                        settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;
                                        
                                        //settings.Columns.Add(column =>
                                        //{
                                        //    column.Caption = "Дата";
                                        //    column.FieldName = "PlannedDate";
                                        //});

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = "Дата";
                                            column.FieldName = "ShowPlannedDate";
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = "Тип";
                                            column.FieldName = "CourseType";
                                        });
                                        
                                        //Добавление комбобоксов
                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdTrainingsCource";
                                            column.Caption = "Рубрика";
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                //comboBoxProperties.DataSource = DB.TrainingsCourses;
                                                comboBoxProperties.DataSource = coursesCol.TrainingsCoursesList;
                                                comboBoxProperties.TextField = "RubricName";
                                                comboBoxProperties.ValueField = "IdTrainingsCourse";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });
                                        //конец комбобокса
                                        
                                        //Добавление комбобоксов
                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdTrainingsCource";
                                            column.Caption = "Курс";
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                //comboBoxProperties.DataSource = DB.TrainingsCourses;
                                                comboBoxProperties.DataSource = coursesCol.TrainingsCoursesList;
                                                comboBoxProperties.TextField = "Name";
                                                comboBoxProperties.ValueField = "IdTrainingsCourse";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });
                                        //конец комбобокса

                                        //Добавление комбобоксов
                                        settings.Columns.Add(column =>
                                        {
                                            column.FieldName = "IdTrainingsPlace";
                                            column.Caption = "Город";
                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                //comboBoxProperties.DataSource = DB.TrainingsPlaces;
                                                comboBoxProperties.DataSource = placesCol.TrainingsPlacesList;
                                                comboBoxProperties.TextField = "TrainingsCityName";
                                                comboBoxProperties.ValueField = "IdTrainingsPlace";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });
                                        //конец комбобокса

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption =  " ";
                                            column.FieldName = "IdTrainingsSchedule";
                                            column.ColumnType = MVCxGridViewColumnType.HyperLink;
                                            column.Settings.AutoFilterCondition = AutoFilterCondition.Contains;
                                            HyperLinkProperties properties = column.PropertiesEdit as HyperLinkProperties;
                                            String urlFormatString = Url.Action("TrainingsPlannedRequestCreate", "TC", new RouteValueDictionary(new { scheduleId = "{0}", username = Page.User.Identity.Name }));
                                            properties.NavigateUrlFormatString = HttpUtility.UrlDecode(urlFormatString);
                                            properties.TextField = "LinkText";
                                        });
                                        
                                    }).Bind(Model).GetHtml();
%>
